package com.bjsxt.wraerClass;

public class MyInteger {
    private int value;
    private static MyInteger[] cache =new MyInteger[256];
    private static final int LOW=-128;
    private static final int HEIGHT = 127;

    static {
        for (int i=LOW;i<=HEIGHT;i++){
            cache[i+128] = new MyInteger(i);
        }
    }

    @Override
    public String toString() {
        return "MyInteger{" +
                "value=" + value +
                '}';
    }

    private MyInteger(int i) {
        this.value=i;
    }

    public static MyInteger valueOf(int i){
        if (i>=LOW&&i<=HEIGHT){
            return cache[i+128];
        }
        return new MyInteger(i);
    }

    public static void main(String[] args) {
        MyInteger m = MyInteger.valueOf(300);
        System.out.println(m);
    }

}
